<!DOCTYPE html>












  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.4.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.4.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.4.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '6.4.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="Docker是什么Docker是Go语言编写的，一种具有虚拟化特性的应用容器引擎，可以理解为一种更轻量级的虚拟机。 应用容器可以视为软件供应链的集装箱，能够把应用需要的运行环境、缓存环境、数据库环境等等封装起来，以最简洁的方式支持应用运行，轻装上阵，因为其同系统共享内核所以性能相比虚拟机更佳。  简单来讲：Docker提供的是应用环境，虚拟机提供的是系统环境">
<meta name="keywords" content="微服务,Docker">
<meta property="og:type" content="article">
<meta property="og:title" content="微服务和Docker的思考">
<meta property="og:url" content="http://yoursite.com/2018/03/01/docker-mic/index.html">
<meta property="og:site_name" content="ThinkMore">
<meta property="og:description" content="Docker是什么Docker是Go语言编写的，一种具有虚拟化特性的应用容器引擎，可以理解为一种更轻量级的虚拟机。 应用容器可以视为软件供应链的集装箱，能够把应用需要的运行环境、缓存环境、数据库环境等等封装起来，以最简洁的方式支持应用运行，轻装上阵，因为其同系统共享内核所以性能相比虚拟机更佳。  简单来讲：Docker提供的是应用环境，虚拟机提供的是系统环境">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-07-09T02:48:36.935Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="微服务和Docker的思考">
<meta name="twitter:description" content="Docker是什么Docker是Go语言编写的，一种具有虚拟化特性的应用容器引擎，可以理解为一种更轻量级的虚拟机。 应用容器可以视为软件供应链的集装箱，能够把应用需要的运行环境、缓存环境、数据库环境等等封装起来，以最简洁的方式支持应用运行，轻装上阵，因为其同系统共享内核所以性能相比虚拟机更佳。  简单来讲：Docker提供的是应用环境，虚拟机提供的是系统环境">






  <link rel="canonical" href="http://yoursite.com/2018/03/01/docker-mic/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>微服务和Docker的思考 | ThinkMore</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?13172698bcdb7ab00b7d3ec112aae9c1";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">ThinkMore</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">驽马十驾,功在不舍！</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />Home</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />Archives</a>
  </li>

      
      
    </ul>
  

  
    

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/03/01/docker-mic/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="文敦复">
      <meta itemprop="description" content="思考的懒惰是真的懒惰！">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="ThinkMore">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">微服务和Docker的思考
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              

              
                
              

              <time title="Created: 2018-03-01 22:29:20" itemprop="dateCreated datePublished" datetime="2018-03-01T22:29:20+08:00">2018-03-01</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Edited on</span>
                
                <time title="Modified: 2018-07-09 10:48:36" itemprop="dateModified" datetime="2018-07-09T10:48:36+08:00">2018-07-09</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/微服务/" itemprop="url" rel="index"><span itemprop="name">微服务</span></a></span>

                
                
                  , 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/微服务/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Docker是什么"><a href="#Docker是什么" class="headerlink" title="Docker是什么"></a>Docker是什么</h2><p>Docker是<code>Go</code>语言编写的，一种具有<code>虚拟化</code>特性的<code>应用容器</code>引擎，可以理解为一种<code>更轻量级</code>的虚拟机。</p>
<p><code>应用容器</code>可以视为软件供应链的集装箱，能够把<code>应用</code>需要的运行环境、缓存环境、数据库环境等等封装起来，以最简洁的方式支持应用运行，轻装上阵，因为其同系统<code>共享内核</code>所以性能相比<code>虚拟机</code>更佳。</p>
<blockquote>
<p>简单来讲：<code>Docker</code>提供的是<code>应用</code>环境，<code>虚拟机</code>提供的是<code>系统</code>环境</p>
</blockquote>
<a id="more"></a>
<h2 id="Docker的优势"><a href="#Docker的优势" class="headerlink" title="Docker的优势"></a>Docker的优势</h2><ul>
<li>应用可以打包部署到Docker后可以保证<code>应用</code>环境在各个阶段的<code>一致性</code>。方便部署，减少运维压力，让开发者更加方便的对应用进行 <code>开发、测试、部署</code>，让应用快速迭代，快速上线。</li>
<li>Docker<code>资源占用少</code>，<code>资源利用率高</code>。因为Docker相比虚拟机而言是直接同宿主机硬件打交道，而虚拟机则是把宿主机的硬件部分也虚拟化了。</li>
<li>Docker打包<code>简单</code>，打包后体积相对于虚拟机小很多，同时部署也是<code>一键部署</code>。</li>
<li>Docker<code>启动速度</code>相当快，比虚拟机快了好几个量级，常规情况下启动时间是以秒为单位。</li>
</ul>
<h2 id="Docker的使用场景"><a href="#Docker的使用场景" class="headerlink" title="Docker的使用场景"></a>Docker的使用场景</h2><h3 id="应用场景1"><a href="#应用场景1" class="headerlink" title="应用场景1"></a>应用场景1</h3><p>在CentOS 6下，我编译了一个so文件，该so文件依赖系统环境的同时依赖了一些动态链接库。</p>
<ul>
<li>我将该so文件，提供给了同事A，同事A在它的Ubuntu系统上因为系统动态库版本不一样，环境有差异，无法运行。</li>
<li>我将该so文件，提供给了同事B，同事B在它的CentOS 7下因为系统动态库版本不一样，环境有差异，无法运行。</li>
<li>我将该so文件，提供给了同事B，同事B在它的CentOS 6下，虽然系统大版本一直了，但是因为没有下载部分依赖项，也无法运行。</li>
</ul>
<p>Docker如何处理这个问题？</p>
<p>我将这个so文件需要的链接库、软件配置等信息打包到Docker中，提供给同事的是将Docker镜像， 同事只需要在其各自系统下安装一次Docker，就可以通过一个简单指令启动运行。</p>
<h3 id="应用场景2"><a href="#应用场景2" class="headerlink" title="应用场景2"></a>应用场景2</h3><p>我需要在Linux下部署RabbitMQ，经过查阅资料我发现大体我需要进行如下步骤</p>
<ol>
<li>根据不同的系统版本，选择安装Erlang环境支持的一大堆库（RabbitMQ）</li>
<li>安装Erlang</li>
<li>下载RabbitMQ的安装包</li>
<li>解压软件压缩包</li>
<li>修改配置</li>
<li>启动RabbitMQ，然后运行。</li>
</ol>
<p>一大堆事情折腾的很累人</p>
<p>Docker如何解决，2行代码：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span># 下载rabbitmq 镜像</span><br><span class="line">docker pull docker.io/rabbitmq</span><br><span class="line"><span class="meta">#</span># 启动</span><br><span class="line">docker run -d --name rabbitmq \</span><br><span class="line">--publish 5671:5671  --publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 \</span><br><span class="line">rabbitmq:management</span><br></pre></td></tr></table></figure>
<blockquote>
<p>下载 RabbitMQ镜像此部分操作其实都可以省略，Docker 会自动检查本地仓库是否存在镜像，如果没有镜像会从Docker Hub官方仓库进行下载。</p>
</blockquote>
<h2 id="Docker同微服务结合"><a href="#Docker同微服务结合" class="headerlink" title="Docker同微服务结合"></a>Docker同微服务结合</h2><p>微服务开发阶段同普通开发一致，无变化。微服务开发完成后进入测试阶段时，结合Docker进行如下操作来将Docker同微服务应用进行结合。</p>
<ol>
<li>编写Docker部署脚本Dockerfile。</li>
<li>利用编写好的Dockerfile进行镜像构建。</li>
<li>启动镜像，进行测试。</li>
<li>修改BUG</li>
<li>重复2，3，4.</li>
<li>服务通过Docker镜像上线。</li>
</ol>
<h2 id="无网环境中Docker更简单"><a href="#无网环境中Docker更简单" class="headerlink" title="无网环境中Docker更简单"></a>无网环境中Docker更简单</h2><p>在我们JG行业中，要将应用部署到服务上，需要在外网下载各种工具包后，在宿主机中单独部署JDK，配置环境变量，安装数据库等一些支撑软件，费事、费力还容易配置错误。</p>
<p>但是Docker制作成镜像后，运行所需的所有环境都被打包进了容器了，只需要在宿主机上安装Docker，后续便能保证运行，部署起来更加简单。</p>
<blockquote>
<p>您有任何建议和意见，请Email联系: <a href="mailto:hicode_club@163.com" target="_blank" rel="noopener">hicode_club@163.com</a></p>
<p>转载请保留出处 <a href="http://www.hicode.club" target="_blank" rel="noopener">HiCode 俱乐部</a></p>
</blockquote>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/03/01/think-copy-on-write/" rel="next" title="我对CopyOnWrite的思考">
                <i class="fa fa-chevron-left"></i> 我对CopyOnWrite的思考
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/03/11/think-foreach/" rel="prev" title="对List遍历过程中添加和删除的思考">
                对List遍历过程中添加和删除的思考 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">文敦复</p>
              <p class="site-description motion-element" itemprop="description">思考的懒惰是真的懒惰！</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">39</span>
                    <span class="site-state-item-name">posts</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">37</span>
                    <span class="site-state-item-name">categories</span>
                  
                </div>
              

              
            </nav>
          

          

          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Docker是什么"><span class="nav-number">1.</span> <span class="nav-text">Docker是什么</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Docker的优势"><span class="nav-number">2.</span> <span class="nav-text">Docker的优势</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Docker的使用场景"><span class="nav-number">3.</span> <span class="nav-text">Docker的使用场景</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#应用场景1"><span class="nav-number">3.1.</span> <span class="nav-text">应用场景1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#应用场景2"><span class="nav-number">3.2.</span> <span class="nav-text">应用场景2</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Docker同微服务结合"><span class="nav-number">4.</span> <span class="nav-text">Docker同微服务结合</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#无网环境中Docker更简单"><span class="nav-number">5.</span> <span class="nav-text">无网环境中Docker更简单</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文敦复</span>

  

  
</div>




  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme – <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Muse</a> v6.4.0</div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.4.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.4.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.4.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.4.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.4.0"></script>



  



  










  





  

  

  

  

  
  

  

  

  

  

  

</body>
</html>
